package test06;

/**
 * 客户端演示代码
 */
public class LLMInferenceClient {
    public static void main(String[] args) {
        System.out.println("🚀 LLM推理服务优化策略模式演示\n");

        // 创建模型
        Model model = new Model("llama-7b-chat");
        model.loadWeights();

        // 创建推理调度器
        InferenceScheduler scheduler = new InferenceScheduler(model);

        // 创建测试请求
        RequestData[] requests = {
                new RequestData("解释人工智能的基本概念", 1),
                new RequestData("写一个关于机器学习的短故事", 2),
                new RequestData("计算1+1等于多少", 3),
                new RequestData("翻译'Hello World'为中文", 1),
                new RequestData("总结Transformer架构", 2)
        };

        // 场景1: 实时对话场景（低延迟）
        System.out.println("=== 场景1: 实时对话场景 ===");
        WorkloadProfile chatProfile = new WorkloadProfile(50, 128, 15.0);
        scheduler.autoSelectStrategy(chatProfile);
        scheduler.executeInference(requests);

        // 场景2: 批量文本生成（高吞吐量）
        System.out.println("\n=== 场景2: 批量文本生成场景 ===");
        WorkloadProfile batchProfile = new WorkloadProfile(2000, 512, 100.0);
        scheduler.autoSelectStrategy(batchProfile);

        // 创建更多请求模拟批量场景
        RequestData[] batchRequests = new RequestData[20];
        for (int i = 0; i < batchRequests.length; i++) {
            batchRequests[i] = new RequestData("批量请求_" + i);
        }
        scheduler.executeInference(batchRequests);

        // 场景3: 代码补全场景（平衡模式）
        System.out.println("\n=== 场景3: 代码补全场景 ===");
        WorkloadProfile codeProfile = new WorkloadProfile(500, 256, 30.0);
        scheduler.autoSelectStrategy(codeProfile);
        scheduler.executeInference(requests);

        // 场景4: 手动策略组合
        System.out.println("\n=== 场景4: 手动策略组合 ===");
        CompositeOptimizationStrategy customStrategy = new CompositeOptimizationStrategy();
        customStrategy.addStrategy(new QuantizationStrategy());
        customStrategy.addStrategy(new ContinuousBatchingStrategy());
        customStrategy.addStrategy(new KernelFusionStrategy());

        scheduler.setStrategy(customStrategy);
        scheduler.executeInference(requests);

        // 场景5: 动态策略切换演示
        System.out.println("\n=== 场景5: 动态策略切换演示 ===");
        System.out.println("模拟负载变化...");

        // 从低负载切换到高负载
        WorkloadProfile lowLoad = new WorkloadProfile(100, 128, 20.0);
        scheduler.autoSelectStrategy(lowLoad);
        scheduler.executeInference(requests);

        WorkloadProfile highLoad = new WorkloadProfile(1500, 512, 80.0);
        scheduler.autoSelectStrategy(highLoad);
        scheduler.executeInference(batchRequests);
    }
}